var dateTimePicker = require('../../../../utils/dateTimePicker.js');
 
page({
    data:{
        date: '2018-10-01',
        time: '12:00',
        dateTimeArray: null,
        dateTime: null,
        dateTimeArray1: null,
        dateTime1: null,
        startTime: '',
        endTime: ''
    },
    onload(){
    var obj1 = dateTimePicker.dateTimePicker('2019', '2100');
    // 精确到分的处理，将数组的秒去掉
    var lastArray = obj1.dateTimeArray.pop();
    var lastTime = obj1.dateTime.pop();
    this.setData({
      dateTimeArray1: obj1.dateTimeArray,
      dateTime1: obj1.dateTime,
      dateTimeArray: obj1.dateTimeArray,
      dateTime: obj1.dateTime,
    });
    },
    changeDateTime(e) {
    let type = e.currentTarget.dataset.type
    if (type == 'start') {
      this.setData({ dateTime1: e.detail.value });
    } else {
      this.setData({ dateTime: e.detail.value });
    }

  },
  changeDateTimeColumn(e) {
    let type = e.currentTarget.dataset.type
    if (type == 'start') {
      var arr = this.data.dateTime1, dateArr = this.data.dateTimeArray1;
      arr[e.detail.column] = e.detail.value;
      dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
      console.log(this.data.startTime)
      this.data.startTime=''
      for (let i = 0; i < dateArr.length; i++) {//开始时间
        if (i == 4) {
          this.data.startTime += dateArr[i][arr[i]]
        } else if (i == 3) {
          this.data.startTime += dateArr[i][arr[i]] + ':'
        } else if (i == 2) {
          this.data.startTime += dateArr[i][arr[i]] + ' '
        } else {
          this.data.startTime += dateArr[i][arr[i]] + '-'
        }
      }
      console.log(this.data.startTime)
      this.setData({
        dateTimeArray1: dateArr,
        dateTime1: arr
      });
    } else {//结束时间
      var arr = this.data.dateTime, dateArr = this.data.dateTimeArray;
      arr[e.detail.column] = e.detail.value;
      dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
      this.data.endTime=''
      for (let i = 0; i < dateArr.length; i++) {
        if (i == 4) {
          this.data.endTime += dateArr[i][arr[i]]
        } else if (i == 3) {
          this.data.endTime += dateArr[i][arr[i]] + ':'
        } else if (i == 2) {
          this.data.endTime += dateArr[i][arr[i]] + ' '
        }else{
          this.data.endTime += dateArr[i][arr[i]] + '-'
        }
      }
      this.setData({
        dateTimeArray: dateArr,
        dateTime: arr
      });
    }
  },
  Change: function (e) {
    const val = e.detail.value
    this.setData({
      year: this.data.years[val[0]],
      month: this.data.months[val[1]],
      day: this.data.days[val[2]],
      hour: this.data.hours[val[3]],
      minute: this.data.minutes[val[4]],
    })
    var totalDay = this.mGetDate(this.data.year, this.data.month);
    var changeDate = [];
    for (let i = 1; i <= totalDay; i++) {
      var k = i;
      if (0 <= i && i < 10) {
        k = "0" + i
      }
      changeDate.push(k)
    }
    this.setData({
      days: changeDate
    })
  },
 
})
